import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import nodejs from '@feidao/web/atom/browser/msg/nodejs';
import get_info from '@feidao/web/atom/browser/storage/get';

export default async function a002(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	// 修改
	const exam_id = fd.data.exam_id;
	// 获取数据
	const exam_name = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="exam_name"]').value;
	if (!exam_name) {
		alert('请输入考试名称');
		return;
	}
	const start_time = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="start_time"]').value;
	if (!start_time) {
		alert('请选择考试日期开始时间');
		return;
	}
	const end_time = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="end_time"]').value;
	if (!end_time) {
		alert('请选择考试日期结束时间');
		return;
	}
	const am_start_time = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="am_start_time"]').value;
	if (!am_start_time) {
		alert('请选择上午开始时间');
		return;
	} else if (am_start_time > '12:00') {
		alert('请选择正确的上午开始时间');
		return;
	}
	const pm_start_time = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="pm_start_time"]').value;
	if (!pm_start_time) {
		alert('请选择下午开始时间');
		return;
	} else if (pm_start_time < '12:00') {
		alert('请选择正确的下午开始时间');
		return;
	}
	// 当前登录用户
	const creater = await get_info('user_code');
	// 调用服务
	const res = await nodejs(fd.data.spaceid, 'exam_upd', { exam_id, exam_name, start_time, end_time, pm_start_time, am_start_time, creater });
	if (res === 'success') {
		alert('编辑成功');
		window.location.reload();
	} else {
		alert('编辑失败');
	}
}
